﻿@using SCMS.Resource
@model SCMS.UI.Models.TravelAuth
@{AjaxOptions ajaxOpts = new AjaxOptions
  {
      UpdateTargetId = "ContentDiv",
      LoadingElementId = "loading",
      HttpMethod = "Post",
      Url = Url.Action("ProceedToTAuthDetails"),
      OnSuccess = string.Format("usermsg('{0}'); ", Resources.Global_String_ProcessCompleted),
      OnFailure = "javascript:errormsg()"
  };}
<script src="@Url.Content("~/Scripts/js/jquery-1.7.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<div class="partialViewCard">
    <div class="partialViewCardHeader">
        <h3>
            @Resources.Global_String_TAFDescription</h3>
    </div>
    @using (Ajax.BeginForm(null, null, ajaxOpts, new { @class = "form", @id = "frmTAuth" }))
    {
        @Html.ValidationSummary(true)
        <br />
        <input type="hidden" id="actionStatus" value="@ViewBag.Response" />
        <input type="hidden" id="statusMsg" value="@ViewBag.msg" />
        
        <table width="98%" align="center" cellpadding="0">
            <tr>
                <th align="center" width="33.3%">
                    @Resources.Global_String_Date
                </th>
                <th align="center" width="33.3%">
                    @Resources.Global_String_TANo
                </th>
                <th align="center" width="33.3%">
                    @Resources.TravelAuth_LoadTAuth_TravellerName
                </th>
            </tr>
            <tr>
                <td align="center">
                    @Html.EditorFor(m => m.EntityTravelAuth.PreparedOn)
                    @Html.ValidationMessageFor(m => m.EntityTravelAuth.PreparedOn, Resources.Global_String_Required)
                </td>
                <td align="center">
                    @Html.TextBoxFor(m => m.EntityTravelAuth.RefNumber, new { id = "refNo", @readonly = "readonly" })
                    @*@readonly = "readonly",placeholder*@
                    @Html.ValidationMessageFor(m => m.EntityTravelAuth.RefNumber, Resources.Global_String_Required)
                </td>
                <td align="center">
                    <table width="100%">
                        <tr>
                            <td>
                                <div id="travellerId">
                                    @Html.DropDownListFor(x => x.EntityTravelAuth.TravellerId, Model.staffs, Resources.Global_String_PleaseSelect)
                                    @Html.ValidationMessageFor(x => x.EntityTravelAuth.TravellerId, Resources.Global_String_Required)
                                    @*   @Html.EditorFor(x => x.EntityTravelAuth.TravelerName)
                                    @Html.ValidationMessageFor(x => x.EntityTravelAuth.TravelerName)
                                    @Html.EditorFor(x => x.EntityTravelAuth.TravelerTitle)
                                    @Html.ValidationMessageFor(x => x.EntityTravelAuth.TravelerTitle)*@
                                </div>
                            </td>
                            @*   <td>
                                <input type="checkbox" />
                                Others
                            </td>*@
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <th align="center">
                    @Resources.TravelAuth_LoadTAuth_Destination
                </th>
                <th align="center">
                    @Resources.TravelAuth_LoadTAuth_TravellType
                </th>
                <th align="center">
                    @Resources.TravelAuth_LoadTAuth_TravellerType
                </th>
            </tr>
            <tr>
                <td align="center">
                    @Html.TextBoxFor(m => m.EntityTravelAuth.Destination)
                    @Html.ValidationMessageFor(m => m.EntityTravelAuth.Destination, Resources.Global_String_Required)
                </td>
                <td align="center">
                    @Html.DropDownListFor(x => x.EntityTravelAuth.TravellType, new SelectList(
                        new List<Object>{ 
                            new { value = "Domestic" , text = Resources.TravelAuth_LoadTAuth_Domestic  },
                            new { value = "International" , text = Resources.TravelAuth_LoadTAuth_International }
                        }, "value", "text"), Resources.Global_String_PleaseSelect)
                    @Html.ValidationMessageFor(x => x.EntityTravelAuth.TravellType, Resources.Global_String_Required)
                </td>
                <td align="center">
                    @Html.DropDownListFor(x => x.EntityTravelAuth.TravellerType, new SelectList(
                        new List<Object>{ 
                            new { value = "Employee" , text = Resources.TravelAuth_LoadTAuth_Employee  },
                            new { value = "Consultant" , text = Resources.TravelAuth_LoadTAuth_Consultant },
                            new { value = "Activity Participant" , text = Resources.TravelAuth_LoadTAuth_ActivityParticipant }
                        }, "value", "text"), Resources.Global_String_PleaseSelect)
                    @Html.ValidationMessageFor(x => x.EntityTravelAuth.TravellerType, Resources.Global_String_Required)
                </td>
            </tr>
            <tr>
                <th align="center">
                    @Resources.TravelAuth_LoadTAuth_TravelStartDate
                </th>
                <th align="center">
                    @Resources.TravelAuth_LoadTAuth_TravelEndDate
                </th>
                <th align="center">
                    @Resources.TravelAuth_LoadTAuth_Totalnoofnights
                </th>
            </tr>
            <tr>
                <td align="center">
                    @Html.EditorFor(m => m.EntityTravelAuth.TravelStartDate)
                    @Html.ValidationMessageFor(m => m.EntityTravelAuth.TravelStartDate, Resources.Global_String_Required)
                </td>
                <td align="center">
                    @Html.EditorFor(x => x.EntityTravelAuth.TravelEndDate)
                    @Html.ValidationMessageFor(x => x.EntityTravelAuth.TravelEndDate, Resources.Global_String_Required)
                </td>
                <td align="center">
                    @Html.EditorFor(x => x.EntityTravelAuth.NoOfNights)
                    @Html.ValidationMessageFor(x => x.EntityTravelAuth.NoOfNights, Resources.Global_String_Required)
                </td>
            </tr>
            <tr>
                <th align="center">
                    @Resources.TravelAuth_LoadTAuth_JourneyFrom
                </th>
                <th align="center">
                    @Resources.TravelAuth_LoadTAuth_JourneyTo
                </th>
                <th align="center">
                    @Resources.TravelAuth_LoadTAuth_Via
                </th>
            </tr>
            <tr>
                <td align="center">
                    @Html.EditorFor(m => m.EntityTravelAuth.FromLocation)
                    @Html.ValidationMessageFor(m => m.EntityTravelAuth.FromLocation, Resources.Global_String_Required)
                </td>
                <td align="center">
                    @Html.EditorFor(m => m.EntityTravelAuth.ToLocation)
                    @Html.ValidationMessageFor(m => m.EntityTravelAuth.ToLocation, Resources.Global_String_Required)
                </td>
                <td align="center">
                    @Html.EditorFor(m => m.EntityTravelAuth.ViaLocation)
                    @Html.ValidationMessageFor(m => m.EntityTravelAuth.ViaLocation, Resources.Global_String_Required)
                </td>
            </tr>
            <tr>
                <th align="center">
                    @Resources.TravelAuth_LoadTAuth_TravelMeans
                </th>
                <th align="left" colspan="2">
                    @Resources.TravelAuth_LoadTAuth_TAFCurrency
                </th>
            </tr>
            <tr>
                <td align="center">
                    @Html.DropDownListFor(x => x.EntityTravelAuth.TravellMeans, new SelectList(
                        new List<Object>{ 
                            new { value = "Air" , text = Resources.TravelAuth_LoadTAuth_Air  },
                            new { value = "Road" , text = Resources.TravelAuth_LoadTAuth_Road },
                            new { value = "Sea" , text = Resources.TravelAuth_LoadTAuth_Sea }
                        }, "value", "text"), Resources.Global_String_PleaseSelect)
                    @Html.ValidationMessageFor(x => x.EntityTravelAuth.TravellMeans, Resources.Global_String_Required)
                </td>
                <td align="center">
                    @Html.DropDownListFor(x => x.EntityTravelAuth.CurrencyId, Model.Currencies, Resources.Global_String_PleaseSelect)
                    @Html.ValidationMessageFor(x => x.EntityTravelAuth.CurrencyId, Resources.Global_String_Required)
                </td>
            </tr>
            <tr>
                <th>
                    @Resources.TravelAuth_LoadTAuth_PurposeofTravel
                </th>
                <td colspan="2">
                    @Html.TextAreaFor(m => m.EntityTravelAuth.TravelPurpose)
                    @Html.ValidationMessageFor(m => m.EntityTravelAuth.TravelPurpose, Resources.Global_String_Required)
                </td>
            </tr>
            <tr>
                <th>
                    @Resources.Global_String_Remarks
                </th>
                <td colspan="2">@Html.TextAreaFor(m => m.EntityTravelAuth.Remarks)
                    @Html.ValidationMessageFor(m => m.EntityTravelAuth.Remarks, Resources.Global_String_Required)
                </td>
            </tr>
        </table>
        <table width="98%" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td width="100%" align="right">
                    <input type="submit" class="btn green" value="  @Resources.Global_String_Proceed  " />
                </td>
            </tr>
        </table>
               if (!ViewBag.Proceed)
               {
                   }
               if (ViewBag.Proceed)
               { 
        <h4 style="text-align: center">
            Travel Dates</h4>
        <center>
            @Ajax.ActionLink("[" + Resources.Global_String_AddNew + "]", "LoadTravelDate", new { TAuthId = ViewBag.TAuthId }, new AjaxOptions
               {
                   OnBegin = string.Format("ShowDialogue('{0}')", Resources.TravelAuth_LoadTAuth_NewTravelDate),
                   UpdateTargetId = "popup-page",
                   LoadingElementId = "popup-loading",
                   OnSuccess = "CenterPopup();"
               })
        </center>

        <table width="98%" align="center" class="cardTable" cellspacing="0" cellpadding="0"
            border="1">
            <tr>
                <th style="width: 10%;">
                    @Resources.TravelAuth_LoadTAuth_TravelDates
                </th>
                <th style="width: 14%;">
                    @Resources.Global_String_Destination
                </th>
                <th style="width: 10%;">
                    @Resources.TravelAuth_LoadTAuth_NoOfNights
                </th>
                <th style="width: 10%;">
                    @Resources.TravelAuth_LoadTAuth_PerDiem
                </th>
                <th style="width: 10%;">
                    @Resources.TravelAuth_LoadTAuth_TotalAllowanceRate
                </th>
                <th style="width: 10%;">
                    @Resources.TravelAuth_LoadTAuth_AdvanceRequired
                </th>
                <th style="width: 10%;">
                    @Resources.Global_String_Currency
                </th>
                <th style="width: 12%;">
                    @Resources.Budget_CategoryList_ProjectNo
                </th>
                <th style="width: 12%;">
                    @Resources.Budget_CreateSubLine_LineNumber
                </th>
            </tr>
            <tbody id="TADateDiv">
                @foreach (var item in Model.TravelDates)
                {
                    <tr>
                        <td align="center">
                            @item.TravalDate.Value.ToShortDateString()
                        </td>
                        <td>
                            @item.Destination
                        </td>
                        <td>
                            @item.NoOfNights
                        </td>
                        <td align="right">
                            @item.DailyPDRate.Value.ToString("##,##0.00")
                        </td>
                        <td align="right">
                            @item.TotalAllowance.Value.ToString("##,##0.00")
                        </td>
                        <td align="right">
                            @item.AdvanceRequired.Value.ToString("##,##0.00")
                        </td>
                        <td>
                            @item.Currency.ShortName
                        </td>
                        <td>
                            @item.ProjectBudget.BudgetCategory.ProjectDonor.ProjectNumber
                        </td>
                        <td>
                            @item.ProjectBudget.LineNumber
                        </td>
                    </tr>
                }
            </tbody>
        </table>

        <h4 style="text-align: center">
            @Resources.TravelAuthorization_LoadTAuth_TravelExpenses</h4>
        <center>
            @Ajax.ActionLink("[" + Resources.Global_String_AddNew + "]", "LoadTravelExpense", new { TAuthId = ViewBag.TAuthId }, new AjaxOptions
               {
                   OnBegin = "ShowDialogue('New Travel Expense')",
                   UpdateTargetId = "popup-page",
                   LoadingElementId = "popup-loading",
                   OnSuccess = "CenterPopup();"
               })
        </center>

        <table width="98%" align="center" class="cardTable" cellspacing="0" cellpadding="0"
            border="1">
            <tr>
                <th style="width: 34%;">
                    @Resources.TravelAuthorization_String_DescriptionOfExpenses
                </th>
                <th style="width: 14%;">
                    @Resources.TravelAuthorization_String_TotalCostOfExpenses
                </th>
                <th style="width: 14%;">
                    @Resources.TravelAuthorization_String_AdvanceRequired
                </th>
                <th style="width: 12%;">
                    @Resources.Global_String_Currency
                </th>
                <th style="width: 12%;">
                    @Resources.Budget_CategoryList_ProjectNo
                </th>
                <th style="width: 12%;">
                    @Resources.Budget_CreateSubLine_LineNumber
                </th>
            </tr>
            <tbody id="TAExpenseDiv">
                @foreach (var item in Model.TravelExpense)
                {
                    <tr>
                        <td>@item.ExpenseDescription
                        </td>
                        <td align="right">@item.TotalCost.Value.ToString("##,##0.00")
                        </td>
                        <td align="right">@item.AdvanceRequired.Value.ToString("##,##0.00")
                        </td>
                        <td>
                            @item.Currency.ShortName
                        </td>
                        <td>
                            @item.ProjectBudget.BudgetCategory.ProjectDonor.ProjectNumber
                        </td>
                        <td>@item.ProjectBudget.LineNumber
                        </td>
                    </tr>
                }
            </tbody>
        </table>

               }

    }
    @if (ViewBag.Proceed)
    {
        <hr />
        <center>
            <input type="button" class="btn green" value="  @Resources.Global_String_SubmitForApproval  " onclick="sendRequest('SubmitTAF/@Model.EntityTravelAuth.Id', 'ContentDiv', 'loading');if (document.getElementById('table') != null) {initSorter(); sorter.size(20); }" />
        </center>
    }
    <br />
</div>
